package com.example.administrator.yanfoxconn.activity;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Rect;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.util.Base64;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.TableRow;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.administrator.yanfoxconn.R;
import com.example.administrator.yanfoxconn.adapter.YJExceZGRecordAdapter;
import com.example.administrator.yanfoxconn.bean.FileName;
import com.example.administrator.yanfoxconn.bean.JVSchoolInfo;
import com.example.administrator.yanfoxconn.bean.KKGWMessage;
import com.example.administrator.yanfoxconn.bean.SelectModel;
import com.example.administrator.yanfoxconn.bean.YJExceMessage;
import com.example.administrator.yanfoxconn.constant.Constants;
import com.example.administrator.yanfoxconn.constant.FoxContext;
import com.example.administrator.yanfoxconn.constant.ImageCaptureManager;
import com.example.administrator.yanfoxconn.intent.PhotoPickerIntent;
import com.example.administrator.yanfoxconn.intent.PhotoPreviewIntent;
import com.example.administrator.yanfoxconn.utils.BaseActivity;
import com.example.administrator.yanfoxconn.utils.FileUtil;
import com.example.administrator.yanfoxconn.utils.HttpConnectionUtil;
import com.example.administrator.yanfoxconn.utils.HttpUtils;
import com.example.administrator.yanfoxconn.utils.ImageZipUtils;
import com.example.administrator.yanfoxconn.utils.TimeDateUtils;
import com.example.administrator.yanfoxconn.utils.ToastUtils;
import com.example.administrator.yanfoxconn.widget.MyGridView;
import com.example.administrator.yanfoxconn.widget.MyListView;
import com.example.administrator.yanfoxconn.widget.TouchImageView;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import org.json.JSONArray;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @Description 關務-設備盤點主界面
 * @Author song
 * @Date 10/19/21 7:21 PM
 */
public class KKCheckMainActivity extends BaseActivity implements View.OnClickListener  {


    private final int MESSAGE_SET_GWYC = 111;//GWYC
    @BindView(R.id.btn_title_left)
    Button btnBack;//返回
    @BindView(R.id.tv_title)
    TextView tvTitle;//標題
    @BindView(R.id.btn_title_right)
    Button btnUp;//提交

    @BindView(R.id.tv_identNo)
    TextView tvIdentNo;//統一識別號
    @BindView(R.id.tv_ControlNo)
    TextView tvControlNo;//管制編號
    @BindView(R.id.tv_RecordName)
    TextView tvRecordName;//備案名稱
    @BindView(R.id.tv_S_Model)
    TextView tvSModel;//規格型號
    @BindView(R.id.tv_PropertyType)
    TextView tvPropertyType;//財產類型
    @BindView(R.id.tv_feeCode)
    TextView tvFeeCode;//費用部門
    @BindView(R.id.tv_Keeper)
    TextView tvKeeper;//保管人
    @BindView(R.id.tv_S_Storage)
    TextView tvSStorage;//存放位置
    @BindView(R.id.tv_InventoryDate)
    TextView tvInventoryDate;//棟盤點日期別
    @BindView(R.id.tv_SupervisionDate)
    TextView tvSupervisionDate;//監管時間
    @BindView(R.id.iv_EQUIPMENTPHOTO)
    TouchImageView tvEquipment;//
    @BindView(R.id.iv_NAMEPLATEPHOTO)
    TouchImageView tvNamePlate;//
    @BindView(R.id.iv_CONTROLPHOTO)
    TouchImageView tvControl;//
    @BindView(R.id.sp_inventory_result)
    Spinner spInventoryResult;//盤點結果
    @BindView(R.id.ll_exce)
    LinearLayout llExce;//異常欄位
    @BindView(R.id.iv_empty)
    ImageView ivEmpty;//空白图片占位
    @BindView(R.id.gv_photo)
    MyGridView gridView;//图片显示区域
    @BindView(R.id.et_exce_desp)
    EditText etExceDesp;//描述
    @BindView(R.id.btn_next)
    Button btnNext;//掃描下一個
    @BindView(R.id.btn_up_photo)
    Button btnUpPhoto;//上傳照片
    @BindView(R.id.btn_finish)
    Button btnFinish;//結束

    private String btnFlag="";//for check()
    private String qrResult="";
    private List<KKGWMessage> message;
    private List<JVSchoolInfo> ycList;
    private String yc,ycFlag="0";
    private static final int REQUEST_CAMERA_CODE = 11;
    private static final int REQUEST_PREVIEW_CODE = 22;
    private ArrayList<String> imagePaths = null;//圖片未壓縮地址
    private ImageCaptureManager captureManager; // 相机拍照处理类
    private GridAdapter gridAdapter;
    private Date curDate = null;//當前時間
    private String curDates;//當前時間
    private SimpleDateFormat formatter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_kk_check_main);
        ButterKnife.bind(this);
        qrResult= getIntent().getStringExtra("result").split("\\(")[0];
        tvTitle.setText("異常詳情");
        btnUp.setOnClickListener(this);
        btnNext.setOnClickListener(this);
        btnUpPhoto.setOnClickListener(this);
        btnFinish.setOnClickListener(this);
        btnBack.setOnClickListener(this);
        ivEmpty.setOnClickListener(this);
        tvEquipment.setOnClickListener(this);
        tvNamePlate.setOnClickListener(this);
        tvControl.setOnClickListener(this);
        int cols = getResources().getDisplayMetrics().widthPixels / getResources().getDisplayMetrics().densityDpi;
        cols = cols < 4 ? 4 : cols;
        gridView.setNumColumns(cols);

        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (position == imagePaths.size()) {
                    PhotoPickerIntent intent = new PhotoPickerIntent(KKCheckMainActivity.this);
                    intent.setSelectModel(SelectModel.MULTI);
                    intent.setShowCarema(true); // 是否显示拍照
                    intent.setMaxTotal(3); // 最多选择照片数量，默认为3
                    intent.setSelectedPaths(imagePaths); // 已选中的照片地址， 用于回显选中状态
                    startActivityForResult(intent, REQUEST_CAMERA_CODE);
                } else {
                    PhotoPreviewIntent intent = new PhotoPreviewIntent(KKCheckMainActivity.this);
                    intent.setCurrentItem(position);
                    intent.setPhotoPaths(imagePaths);
                    startActivityForResult(intent, REQUEST_PREVIEW_CODE);
                }
            }
        });

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_title_left:
                finish();
                break;
            case R.id.btn_next:
                btnFlag="next";
                if (etExceDesp.getText().toString().equals("")&&!ycFlag.equals("0")){
                    ToastUtils.showShort(KKCheckMainActivity.this,"請輸入異常原因");
                }else {
                    check();
                }
                break;
            case R.id.btn_finish://
//                if (flag.equals("end")){
//                    aboutAlert("確定要結案嗎", 111);
//                }else {
//                    aboutAlert(getResources().getString(R.string.update_confirm), Constants.MESSAGE_UP);
//                }
                btnFlag="finish";
                if (etExceDesp.getText().toString().equals("")&&!ycFlag.equals("0")){
                    ToastUtils.showShort(KKCheckMainActivity.this,"請輸入異常原因");
                }else {
                    check();
                }
                break;
            case R.id.iv_empty:
                PhotoPickerIntent intent = new PhotoPickerIntent(KKCheckMainActivity.this);
                intent.setSelectModel(SelectModel.MULTI);
                intent.setShowCarema(true); // 是否显示拍照
                intent.setMaxTotal(3); // 最多选择照片数量，默认为3
                intent.setSelectedPaths(imagePaths); // 已选中的照片地址， 用于回显选中状态
                startActivityForResult(intent, REQUEST_CAMERA_CODE);
                break;
            case R.id.btn_up_photo:
                Log.e("-------","upPhoto");
                Intent intent1 = new Intent(KKCheckMainActivity.this,CarListUpActivity.class);
                intent1.putExtra("from","KK");
                intent1.putExtra("isEQNull",message.get(0).getEQUIPMENTPHOTO().equals(""));
                intent1.putExtra("isNANull",message.get(0).getNAMEPLATEPHOTO().equals(""));
                intent1.putExtra("isCONull",message.get(0).getCONTROLPHOTO().equals(""));
                intent1.putExtra("sId",qrResult);
                startActivity(intent1);
                break;
            case R.id.iv_EQUIPMENTPHOTO:
                if (message!=null&&message.get(0).getEQUIPMENTPHOTO().equals("")){
                    ToastUtils.showShort(KKCheckMainActivity.this,"請點擊'提交照片'按鈕！");
                }else {
                    showPhoto(message.get(0).getEQUIPMENTPHOTO(), tvEquipment);
                }
                break;
            case R.id.iv_NAMEPLATEPHOTO:
                if (message!=null&&message.get(0).getNAMEPLATEPHOTO().equals("")){
                ToastUtils.showShort(KKCheckMainActivity.this,"請點擊'提交照片'按鈕！");
            }else {
                    showPhoto(message.get(0).getNAMEPLATEPHOTO(), tvNamePlate);
                }
                break;
            case R.id.iv_CONTROLPHOTO:
                if (message!=null&&message.get(0).getCONTROLPHOTO().equals("")){
                    ToastUtils.showShort(KKCheckMainActivity.this,"請點擊'提交照片'按鈕！");
                }else {
                    showPhoto(message.get(0).getCONTROLPHOTO(), tvControl);
                }
                break;
        }
    }

    private void getMessage(String keeper,String id) {
        String nameE = "";

        try {//姓名改為工號
            nameE = URLEncoder.encode(URLEncoder.encode(FoxContext.getInstance().getLoginId(), "UTF-8"), "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

        showDialog();

        final String url = Constants.HTTP_GW_GET_INFO + "?keeper=" + nameE + "&id=" + id;
        Log.e("-----------", "url==" + url);
        new Thread() {
            @Override
            public void run() {
                //把网络访问的代码放在这里
                String result = HttpUtils.queryStringForGet(url);
                dismissDialog();
                Gson gson = new Gson();
                if (result != null) {
                    Log.e("---------", "result==fff===" + result);
                    JsonObject jsonObject = new JsonParser().parse(result).getAsJsonObject();
                    String errCode = jsonObject.get("errCode").getAsString();
                    if (errCode.equals("200")) {
                        JsonArray array = jsonObject.get("data").getAsJsonArray();

                        message = new ArrayList<KKGWMessage>();
                        for (JsonElement type : array) {
                            KKGWMessage humi = gson.fromJson(type, KKGWMessage.class);
                            message.add(humi);
                        }

                        Message message = new Message();
                        message.what = Constants.MESSAGE_SET_TEXT;
                        message.obj = jsonObject.get("errMessage").getAsString();
                        mHandler.sendMessage(message);

                    } else {
                        Log.e("-----------", "result==" + result);
                        Message message = new Message();
                        message.what = Constants.MESSAGE_TOAST;
                        message.obj = jsonObject.get("errMessage").getAsString();
                        mHandler.sendMessage(message);
                    }
                } else {
                    Message message = new Message();
                    message.what = Constants.MESSAGE_NETMISTAKE;
                    mHandler.sendMessage(message);
                    finish();
                }
            }
        }.start();
    }
        Handler mHandler = new Handler() {
            public void handleMessage(Message msg) {
                switch (msg.what) {
////                    case MESSAGE_TOAST://Toast彈出
//                        ToastUtils.showLong(KKCheckMainActivity.this, msg.obj.toString());
//                        finish();
//                        break;
                    case Constants.MESSAGE_TOAST://Toast彈出
//                        aboutAlert(msg.obj.toString(),Constants.MESSAGE_TOAST);
                        if (btnFlag.equals("next")){
                            ToastUtils.showLong(KKCheckMainActivity.this, msg.obj.toString());

                            Intent intent = new Intent(KKCheckMainActivity.this,QrCodeActivity.class);
                            intent.putExtra("title", "掃描二維碼");
                            intent.putExtra("num", "KK");
                            startActivity(intent);
                            finish();
                        }else {
                            ToastUtils.showLong(KKCheckMainActivity.this, msg.obj.toString());
                            finish();
                        }
                        break;
                    case MESSAGE_SET_GWYC:
                        setYC();
                        break;
                    case Constants.MESSAGE_NETMISTAKE://Toast彈出
                        ToastUtils.showLong(KKCheckMainActivity.this,R.string.net_mistake);
                        break;
                    case Constants.MESSAGE_SET_TEXT://text賦值
                        if (message!=null&&message.size()!=0) {
                            tvIdentNo.setText(message.get(0).getIDENTNO());
                            tvControlNo.setText(message.get(0).getCONTROLNO());
                            tvRecordName.setText(message.get(0).getRECORDNAME());
                            tvSModel.setText(message.get(0).getS_MODEL());
                            tvPropertyType.setText(message.get(0).getPROPERTYTYPE());
                            tvFeeCode.setText(message.get(0).getFEECODE());
                            tvKeeper.setText(message.get(0).getKEEPER());
                            tvSStorage.setText(message.get(0).getS_STORAGE());
                            tvInventoryDate.setText(message.get(0).getINVENTORYDATE());
                            formatter = new SimpleDateFormat("yyyy-MM-dd");
                            curDate = new Date(System.currentTimeMillis());
                            String[] ddd=message.get(0).getCLEARANCEDATE().split(" ")[0].split("/");
                            tvSupervisionDate.setText(TimeDateUtils.monthCha(formatter.format(curDate),ddd[2]+"-"+ddd[0]+"-"+ddd[1])+"");
                            getInfo("GWYC");

                            if (!message.get(0).getEQUIPMENTPHOTO().equals("")) {
                                byte[] decode = Base64.decode(message.get(0).getEQUIPMENTPHOTO(), Base64.DEFAULT);
                                Bitmap bitmap = BitmapFactory.decodeByteArray(decode, 0, decode.length);
                                tvEquipment.setAdjustViewBounds(true);
                                tvEquipment.setImageBitmap(bitmap);
                            }
                            if (!message.get(0).getNAMEPLATEPHOTO().equals("")) {
                                byte[] decode = Base64.decode(message.get(0).getNAMEPLATEPHOTO(), Base64.DEFAULT);
                                Bitmap bitmap = BitmapFactory.decodeByteArray(decode, 0, decode.length);
                                tvNamePlate.setAdjustViewBounds(true);
                                tvNamePlate.setImageBitmap(bitmap);
                            }
                            if (!message.get(0).getCONTROLPHOTO().equals("")) {
                                byte[] decode = Base64.decode(message.get(0).getCONTROLPHOTO(), Base64.DEFAULT);
                                Bitmap bitmap = BitmapFactory.decodeByteArray(decode, 0, decode.length);
                                tvControl.setAdjustViewBounds(true);
                                tvControl.setImageBitmap(bitmap);
                            }
                        }else{
                            finish();
                            ToastUtils.showLong(KKCheckMainActivity.this, "此設備無資料，請後台確認！");
                        }
                        break;
                    case Constants.MESSAGE_UP://提交響應
//                        worningAlert(msg.obj.toString(),Constants.MESSAGE_TOAST);
//                    ToastUtils.showLong(CrossScanActivity.this, msg.obj.toString());
                        break;
                    case Constants.MESSAGE_JUMP://跳轉維護異常界面
//                        worningAlert(msg.obj.toString(),Constants.MESSAGE_JUMP);
                        break;
                }
                super.handleMessage(msg);
            }
        };

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {

            switch (requestCode) {
                // 选择照片
                case REQUEST_CAMERA_CODE:
                    loadAdpater(data.getStringArrayListExtra(PhotoPickerActivity.EXTRA_RESULT));
                    break;
                // 预览
                case REQUEST_PREVIEW_CODE:
                    loadAdpater(data.getStringArrayListExtra(PhotoPreviewActivity.EXTRA_RESULT));
                    break;
                // 调用相机拍照
                case ImageCaptureManager.REQUEST_TAKE_PHOTO:
                    if (captureManager.getCurrentPhotoPath() != null) {
                        captureManager.galleryAddPic();
                        ArrayList<String> paths = new ArrayList<>();
                        paths.add(captureManager.getCurrentPhotoPath());
                        loadAdpater(paths);
                        Log.e("==========", paths.get(1));
                    }
                    break;
            }
        }
    }
    private void loadAdpater(ArrayList<String> paths) {

        if (imagePaths == null) {
            imagePaths = new ArrayList<>();
        }
        imagePaths.clear();
        imagePaths.addAll(paths);

        if (paths.size() > 0) {
            ivEmpty.setVisibility(View.GONE);
        } else {
            ivEmpty.setVisibility(View.VISIBLE);
        }

        try {
            JSONArray obj = new JSONArray(imagePaths);
            Log.e("--", obj.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }

        if (gridAdapter == null) {
            gridAdapter = new GridAdapter(imagePaths);
            gridView.setAdapter(gridAdapter);
            Log.e("----------------", "ddd==" + imagePaths.size());
        } else {
            gridAdapter.notifyDataSetChanged();
        }

    }
    private class GridAdapter extends BaseAdapter {
        private ArrayList<String> listUrls;

        public GridAdapter(ArrayList<String> listUrls) {
            this.listUrls = listUrls;
        }

        @Override
        public int getCount() {
            if (listUrls.size() == 3) {
                return 3;
            } else {
                return listUrls.size() + 1;
            }

        }

        @Override
        public String getItem(int position) {
            return listUrls.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ImageView imageView;
            if (convertView == null) {
                convertView = getLayoutInflater().inflate(R.layout.item_image, null);
                imageView = (ImageView) convertView.findViewById(R.id.imageView);
                convertView.setTag(imageView);
                // 重置ImageView宽高
//                LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(columnWidth, columnWidth);
//                imageView.setLayoutParams(params);
            } else {
                imageView = (ImageView) convertView.getTag();
            }
            if (position == listUrls.size()) {
                imageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.mipmap.icon_addpic_unfocused));
                if (position == 3) {
                    imageView.setVisibility(View.GONE);
                }
            } else {
                Glide.with(KKCheckMainActivity.this)
                        .load(new File(getItem(position)))
                        .placeholder(R.mipmap.default_error)
                        .error(R.mipmap.default_error)
                        .centerCrop()
                        .crossFade()
                        .into(imageView);
            }
            return convertView;
        }
    }
    //基本信息下拉   傳值：flag GWYC:關務異常
    private void getInfo(String flag){
        new Thread() {
            @Override
            public void run() {
                String url2 = Constants.HTTP_RZXQ_GET_INFO + "?flag=" + flag;

                Log.e("---------", "url2==fff===" + url2);
                //把网络访问的代码放在这里
                String result = HttpUtils.queryStringForPost(url2);
                dismissDialog();
                Gson gson = new Gson();
                if (result != null) {
                    Log.e("---------", "result==fff===" + result);
                    JsonObject jsonObject = new JsonParser().parse(result).getAsJsonObject();
                    String errCode = jsonObject.get("errCode").getAsString();
                    if (errCode.equals("200")) {
                        JsonArray array = jsonObject.get("data").getAsJsonArray();
                            ycList = new ArrayList<JVSchoolInfo>();

                            for (JsonElement type : array) {
                                JVSchoolInfo humi = gson.fromJson(type, JVSchoolInfo.class);
                                ycList.add(humi);
                            }
                            Message message = new Message();
                            message.what = MESSAGE_SET_GWYC;
                            message.obj = jsonObject.get("errMessage").getAsString();
                            mHandler.sendMessage(message);
                    }
                } else {
                    Message message = new Message();
                    message.what = Constants.MESSAGE_NETMISTAKE;
                    mHandler.sendMessage(message);
                    finish();
                }
            }
        }.start();
    }
    private void setYC(){
        List<String> ycName=new ArrayList<>();
        for (int i = 0;i<ycList.size();i++){
            ycName.add(ycList.get(i).getNAME());
        }
        //稽核課隊下拉列表選擇
        spInventoryResult.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, ycName));
        spInventoryResult.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                String str = ycName.get(position);
                yc=ycName.get(position);
                ycFlag=ycList.get(position).getSTATUS();
                if (!ycFlag.equals("0")){
                    llExce.setVisibility(View.VISIBLE);
                }else{
                    llExce.setVisibility(View.GONE);
                }
                Log.e("---------", "最喜欢的水果是：" + str);
//            paramMap.put("kedui",str);
            }
            @Override
            public void onNothingSelected(AdapterView<?> parent) {
            }
        });
    }
    //提交前檢查
    private void check() {
        final String url = Constants.HTTP_GW_SCAN_OK; //此處寫上自己的URL

        JsonObject object = new JsonObject();
        object.addProperty("sId",qrResult);
        object.addProperty("creator", FoxContext.getInstance().getLoginId());
        object.addProperty("sResult", etExceDesp.getText().toString());
        object.addProperty("lat",FoxContext.getInstance().getLocation().getLatitude());
        object.addProperty("lng", FoxContext.getInstance().getLocation().getLongitude());
        object.addProperty("sYCFlag", ycFlag);
        object.addProperty("CustomsCode", message.get(0).getCUSTOMSCODE());
        object.addProperty("feeCode", message.get(0).getFEECODE());
        if (ycFlag.equals("0")){

            object.addProperty("sResult", "正常");

            JsonArray photoArray = new JsonArray();

            object.add("photo", photoArray);
        }else if ((imagePaths == null || imagePaths.size() == 0)&&!ycFlag.equals("0")) {
            ToastUtils.showShort(this, "請拍照或選擇圖片");
        }else {
            JsonArray photoArray = new JsonArray();

            for (int i = 0; i < imagePaths.size(); i++) {

                final String pic_path = imagePaths.get(i);
                String sign_dir = Environment.getExternalStorageDirectory() + File.separator + "YanFoxconn" + File.separator + "Photos";
                String _path = sign_dir + File.separator + System.currentTimeMillis() + i + ".jpg";
//                调用压缩图片的方法，返回压缩后的图片path
                final String compressImage = ImageZipUtils.compressImage(pic_path, _path, 50);
                String picBase64Code = ImageZipUtils.imageToBase64(compressImage);
                //Log.e("---picBase64Code---", "===="+ picBase64Code);
                JsonObject jsonObject1 = new JsonObject();
                jsonObject1.addProperty("file", picBase64Code);
                photoArray.add(jsonObject1);
            }
            object.add("photo", photoArray);
        }
            Log.e("-----object------",  object.toString());

            //開啟一個新執行緒，向伺服器上傳資料
            new Thread() {
                public void run() {
                    //把网络访问的代码放在这里
                    try {
                        showDialog();
                        Log.e("---------", "==fff===" + url);
                        String result = HttpConnectionUtil.doPostJsonObject(url, object);
                        if (result != null) {
                            dismissDialog();
                            Log.e("---------", "result==fff===" + result);
                            JsonObject jsonObject = new JsonParser().parse(result).getAsJsonObject();
                            String errCode = jsonObject.get("errCode").getAsString();
                            if (errCode.equals("200")) {
                                Message message = new Message();
                                message.what = Constants.MESSAGE_TOAST;
                                message.obj = jsonObject.get("errMessage").getAsString();
                                mHandler.sendMessage(message);

                            } else{
                                Message message = new Message();
                                message.what = Constants.MESSAGE_TOAST;
                                message.obj = jsonObject.get("errMessage").getAsString();
                                mHandler.sendMessage(message);
                            }
                        }else{
                            Message message = new Message();
                            message.what = Constants.MESSAGE_NETMISTAKE;
                            mHandler.sendMessage(message);
                            finish();
                        }

                    } catch (Exception e) {
                        e.printStackTrace();
                    }finally {
                        FileUtil.deletePhotos(KKCheckMainActivity.this);
                    }
                }
            }.start();

    }

    private void showPhoto(String photo64,View view){
        int[] location = new int[2];
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Rect frame = new Rect();
            getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
            int statusBarHeight = frame.top;

            view.getLocationOnScreen(location);
            location[1] += 0;
        } else {
            view.getLocationOnScreen(location);
        }
        view.invalidate();
        int width = view.getWidth();
        int height = view.getHeight();

        Intent intent = new Intent(KKCheckMainActivity.this, BigImageActivity.class);
        Bundle b = new Bundle();
        b.putString(BigImageActivity.QR_IMAGE_URL, photo64);
        intent.putExtras(b);
//                                intent.putExtra(BigImageActivity.PHOTO_SELECT_POSITION,);
        intent.putExtra(BigImageActivity.PHOTO_SELECT_X_TAG, location[0]);
        intent.putExtra(BigImageActivity.PHOTO_SELECT_Y_TAG, location[1]);
        intent.putExtra(BigImageActivity.PHOTO_SELECT_W_TAG, width);
        intent.putExtra(BigImageActivity.PHOTO_SELECT_H_TAG, height);
        startActivity(intent);
        overridePendingTransition(0, 0);
    }

    @Override
    protected void onStart() {
        if (!ycFlag.equals("0")){}else{
        getMessage(FoxContext.getInstance().getLoginId(),qrResult);}
        super.onStart();
    }
}
